package com.itheima.blog.web.controller;


import com.itheima.blog.web.entity.WebUser;
import com.itheima.blog.web.service.IWebUserService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sj
 * @since 2023-07-11
 */
@RestController
@RequestMapping("/web/user")
@RequiredArgsConstructor
public class WebUserController {

    private final IWebUserService userService;

    @GetMapping("/name")
    public List<Integer> queryWebUsersByName(String name){
        List<WebUser> list = userService.lambdaQuery()
                .like(StringUtils.isNotBlank(name), WebUser::getName, name)
                .list();
        return list.stream().map(WebUser::getId).collect(Collectors.toList());
    }

    @GetMapping("/ids")
    public List<WebUser> queryWebUsersByIds(List<Long> userIds){
        return userService.getBaseMapper().selectBatchIds(userIds);
    }

    @GetMapping("id")
    public WebUser queryWebUserById(Long userId){
        return userService.getById(userId);
    }


}
